package com.bugstack.springframework.beans.factory.support;

import com.bugstack.springframework.beans.BeansException;
import com.bugstack.springframework.beans.factory.config.BeanDefinition;


/**
 * 在这个类中具体的去实例化Bean
 */
public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFactory {
    @Override
    protected Object createBean(String beanName, BeanDefinition beanDefinition) {
        Object bean;
        try {
            bean = beanDefinition.getBeanClass().newInstance();//实例化bean,注意这里并没有考虑有构造函数的入参，后续03工程中会解决这个问题
        } catch (InstantiationException | IllegalAccessException e) {
            throw new BeansException("Instantiation of bean failed", e);

        }

        addSingleton(beanName,bean);
        return bean;
    }
}
